#include "GUIImage.h"
GUIImage::GUIImage()
{	

}

GUIImage::GUIImage(int id)
{
	m_pMainTexture = ResourceManager::GetInstance()->getTextureByID(id);
}

GUIImage::~GUIImage(){}
bool GUIImage::Init()
{
	return false;
}
void GUIImage::Render()
{
		m_BkgdCenter = D3DXVECTOR3((m_Border.left + m_Border.right)/2.0f, (m_Border.top + m_Border.bottom)/2.0f, 0.0f);
		D3DXVECTOR3 pos;
		//pos = D3DXVECTOR3((m_Border.right - m_Border.left)/2.0f, (m_Border.bottom - m_Border.top)/2.0f,0.0f);
		pos = D3DXVECTOR3(0, 0, 0);


		HR(m_pSprite->Begin(D3DXSPRITE_ALPHABLEND));
		
		RECT bRect;
		bRect.left = 0;
		bRect.right = 500;
		bRect.bottom = 500;
		bRect.top = 0;

		D3DXMATRIX mat, mTrans;
		//D3DXMatrixTranslation(&mat, 20, 20, 0);
		D3DXMatrixTranslation(&mTrans, (m_Border.right - m_Border.left)/2.0f, (m_Border.bottom - m_Border.top)/2.0f,0.0f);
		D3DXMatrixRotationZ(&mat, -D3DX_PI/2.0f);
		//D3DXMatrixRotation(&mat, 90.0f, 0, 0, 1.0f);
		
		D3DXMatrixMultiply(&mat, &mat, &mTrans);
		m_pSprite->SetTransform(&mat);

		HR(m_pSprite->Draw(m_pMainTexture, &bRect, &m_BkgdCenter, &pos, D3DCOLOR_XRGB(255, 255, 255)));

		//Submit all batch to device. Clear of batchs after begin
		HR(m_pSprite->Flush());
		//End drawing
		HR(m_pSprite->End())
}

void GUIImage::SetBorder(float left, float top, float right, float bottom)
{
	m_Border.left = left;
	m_Border.top = top;
	m_Border.right = right;
	m_Border.bottom = bottom;
}